Skip to content

Add implicit solvers for heat conduction equation #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 5, 2025

Conversation

MasanoriKanamaru
Copy link
Member

@MasanoriKanamaru MasanoriKanamaru commented Apr 16, 2025

Summary

This PR adds support for multiple numerical solvers for the heat conduction equation. In addition to the existing explicit Euler method, implicit Euler and Crank-Nicolson methods are now available, providing better stability and accuracy options.

Changes

  • Renamed solver types for clarity:
    • ForwardEulerSolverExplicitEulerSolver
    • BackwardEulerSolverImplicitEulerSolver
  • Fixed boundary condition implementation for implicit methods
    • Boundary conditions are now properly incorporated into the tridiagonal matrix system
    • Added support for isothermal, insulation, and radiation boundary conditions
    • Added analytical solution for 1D heat equation for validation
    • Added comprehensive boundary condition tests

Usage

# Explicit Euler (conditionally stable, fast)
SOLVER = ExplicitEulerSolver(thermo_params)

# Implicit Euler (unconditionally stable, 1st order)
SOLVER = ImplicitEulerSolver(thermo_params)

# Crank-Nicolson (unconditionally stable, 2nd order)
SOLVER = CrankNicolsonSolver(thermo_params)

Breaking Changes

  • ForwardEulerSolverExplicitEulerSolver
  • BackwardEulerSolverImplicitEulerSolver

Tests

All tests pass, including new boundary condition tests. In future pull requests, add further tests for each solver and boundary condition.

Copy link

codecov bot commented Apr 16, 2025

Codecov Report

Attention: Patch coverage is 85.81081% with 21 lines in your changes missing coverage. Please review.

Project coverage is 94.02%. Comparing base (f97da60) to head (578cbcf).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/heat_conduction.jl 84.55% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #161      +/-   ##
==========================================
+ Coverage   93.99%   94.02%   +0.02%     
==========================================
  Files          11       12       +1     
  Lines         683      786     +103     
==========================================
+ Hits          642      739      +97     
- Misses         41       47       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Implement implicit Euler and Crank-Nicolson methods.
Use `x` for the solution vector in each solver as temperature at the next time step, instead of `T`.
- forward Euler -> implicit Euler
- backward Euler -> explicit Euler
Previously, boundary conditions were applied after solving the tridiagonal system, which resulted in incorrect temperature values. This commit fixes the implementation by properly incorporating boundary conditions into the matrix coefficients before solving.

Changes:
  - Isothermal BC: Set matrix row to enforce T[i] = T_iso directly
  - Insulation BC: Use ghost point method to enforce ∂T/∂z = 0
  - Radiation BC: Keep as post-processing due to nonlinearity
  - Apply same fix to both Implicit Euler and Crank-Nicolson methods

  Add comprehensive boundary condition tests:
  - Test isothermal BC with non-zero temperatures (T_upper=100, T_lower=50)
  - Test insulation BC at lower boundary
  - Verify that boundary conditions are correctly satisfied
  - Add tests to main test suite in runtests.jl

This ensures that the implicit methods work correctly for all types of boundary conditions, not just the special case where T=0 at boundaries.
@MasanoriKanamaru MasanoriKanamaru changed the title More solvers Add implicit solvers Jun 4, 2025
@MasanoriKanamaru MasanoriKanamaru changed the title Add implicit solvers Add implicit solvers for heat conduction equation Jun 4, 2025
@MasanoriKanamaru MasanoriKanamaru requested a review from Copilot June 4, 2025 17:14
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces two new implicit solvers (Implicit Euler and Crank–Nicolson) for the 1D heat conduction equation, renames the existing forward/backward Euler types for clarity, and enhances boundary‐condition support and testing.

  • Renamed ForwardEulerSolverExplicitEulerSolver and BackwardEulerSolverImplicitEulerSolver.
  • Implemented proper incorporation of isothermal, insulation, and radiation boundary conditions into the implicit solvers’ tridiagonal systems.
  • Added an analytical solution module plus new tests covering boundary conditions and solver accuracy.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/TPM.jl Renamed solver types and removed duplicate broadcast call.
src/heat_conduction.jl Updated dispatch to use new solver names and fields.
src/heat_conduction_analytical.jl Added analytical solution function with documentation.
test/heat_conduction_1D.jl Updated tests for all three solvers and added error function.
test/test_boundary_conditions.jl New tests for isothermal and insulation boundary conditions.
test/thermal_radiation.jl Updated to use ExplicitEulerSolver.
other test/TPM_*/*.jl files Replaced legacy ForwardEulerSolver with ExplicitEulerSolver.
Comments suppressed due to low confidence (3)

test/heat_conduction_1D.jl:15

  • Typo in the comment: change 'Seeting' to 'Setting' to improve readability.
##= Seeting of time step =##

src/TPM.jl:20

  • [nitpick] Field name x is ambiguous; consider renaming it to something more descriptive (e.g., T_next or next_temperature) for clarity.
    x::Vector{Float64}  # Temperature vector for the next time step

test/test_boundary_conditions.jl:1

  • Tests cover isothermal and insulation BCs, but there’s no coverage for RadiationBoundaryCondition in the heat‐conduction solvers—adding such a case would ensure full BC validation.
@testset "Boundary Conditions" begin

@MasanoriKanamaru MasanoriKanamaru marked this pull request as ready for review June 4, 2025 17:15
- Zero-conductivity case -> Calculate the radiative equilibrium temperature.
- Non-zero conductivity case -> Call a numerical solution method to calculate the temperature.
- Replace the Unicode middle dot (・) with ASCII caret (^) in the docstring of `heat_conduction_analytical.jl` to fix the "invalid escape sequence" error in Julia 1.6.
- This ensures compatibility with Julia 1.6 while maintaining the visual clarity of the ASCII art diagram.
@MasanoriKanamaru MasanoriKanamaru merged commit 45682a6 into main Jun 5, 2025
25 of 29 checks passed
@MasanoriKanamaru MasanoriKanamaru deleted the feature/solvers branch June 5, 2025 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant